<template>
  <div class="good_list">
    <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onPageLoad">
      <van-cell v-for="item in list" :key="item">
        <div class="good_item_box" @click="">
          <div v-if="item.recommendStatus" class="list-item-badge">推荐</div>
          <img style="width: 100%;height: 100%;" :src="item.pic" />
          <div class="good_item">
            <span>{{ item.name }}</span>
            <span>¥{{ item.minPrice }}</span>
            <van-button type="primary" size="small" plain class="buy_but">购买</van-button>
          </div>
        </div>
      </van-cell>
    </van-list>
    <div style="height: 50px;"></div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref, unref } from 'vue';
import useList from './hook';
// import { useFetchSelect } from './hook';

let { list, pageSize, page, finished, loading, getList, onPageLoad } = useList()

// console.log(list);
onMounted(() => {
  getList()
})
// const page = ref(1);
// const pageSize = ref(10);
//   onLoad()
// })
// const list = ref<Record<string, any>>([]);
// const loading = ref(false);
// const finished = ref(false);


//加载数据

// const onLoad = () => {
//   //表示正在发送异步请求，此时不会触发 load 事件
//   loading.value = true;
//   api.goodsList({ page: unref(page), pageSize: unref(pageSize) }).then((res) => {
//     //返回数据
//     const records = res.data?.result ?? [];
//     //总条数
//     const total = res.data?.totalRow ?? 0;

//     list.value = unref(page) === 1 ? unref(records) : [...unref(list), ...records]
//     loading.value = false; //加载完成
//     finished.value = unref(list).length >= total
//   })
//   // 加载状态结束
//   loading.value = false;

//   // 数据全部加载完成
//   if (list.value.length >= 40) {
//     finished.value = true;
//   }
// };

</script>

<style lang="scss" scoped>
.good_list {
  .good_item_box {
    position: relative;

    .list-item-badge {
      position: absolute;
      top: 15px;
      left: 0;
      z-index: 20;
      display: inline-block;
      padding: 2px 4px;
      color: var(--white);
      background-color: var(--red-color);
      font-size: 10px;
      line-height: normal;
      border-radius: 0 8px 8px 0;
      padding-right: 6px;
    }

    .good_item {
      display: flex;
      align-items: center;
      justify-content: space-around;

      &>span:first-child {
        width: 200px;
        /*多行文本省略*/
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
      }



    }
  }
}
</style>